package programer.interviewer.link;

import java.util.HashSet;

public class Question9 {
    public ListNode removeDuplicateNodes(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode res = head;
        HashSet<Integer> set = new HashSet<>();
        set.add(head.val);

        while(head != null && head.next != null) {
            if (set.contains(head.next.val)) {
                head.next = head.next.next;
            } else {
                set.add(head.next.val);
                head = head.next;
            }
        }
        return res;
    }



    public static void main(String[] args) {
        new Question9().removeDuplicateNodes(null);
    }
}
